package com.ng.desktop.hr.view.customer;

import java.awt.event.MouseEvent;

import javax.swing.JOptionPane;

import com.ng.desktop.hr.model.Customer;
import com.ng.desktop.hr.persistence.CustomerPersistence;
import com.ng.desktop.hr.services.NGFactoryBean;
import com.ng.framework.view.desktop.NGEntitySelectorField;

public class CustomerEntitySelector extends NGEntitySelectorField<Customer, CustomerPersistence> {

	private static final long serialVersionUID = -2844474271507747895L;

	@Override
	public void select() {

		if (this.ngEntitySelectorDialog == null) {
			this.ngEntitySelectorDialog = new CustomerEntitySelectorDialog(JOptionPane.getFrameForComponent(this), this);
		}

		ngEntitySelectorDialog.setLocationRelativeTo(this);
		ngEntitySelectorDialog.setVisible(true);
		ngEntitySelectorDialog.toFront();

	}

	@Override
	public void edit() {

		CustomerPersistence customerPersistence = (CustomerPersistence) NGFactoryBean.getInstance()
				.getBean("customerPersistence");

		CustomerEditDialog customerEditDialog = new CustomerEditDialog(JOptionPane.getFrameForComponent(this), customerPersistence, this.getEntity(), this);

		customerEditDialog.setLocationRelativeTo(this);
		customerEditDialog.setVisible(true);
		customerEditDialog.toFront();

	}

}
